<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="120px"
    >
      <el-form-item label="试卷名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入试卷名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="试卷总分" prop="score">
        <el-input
          v-model="queryParams.score"
          placeholder="请输入试卷总分"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试时长(分钟)" prop="duration">
        <el-input
          v-model="queryParams.duration"
          placeholder="请输入考试时长(分钟)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="试卷平均难度" prop="difficulty">
        <el-input
          v-model="queryParams.difficulty"
          placeholder="请输入试卷平均难度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="试卷分类" prop="paperType">
        <el-input
          v-model="queryParams.paperTypeName"
          placeholder="请选择试卷分类"
          clearable
          :style="{width: '100%'}"
          @focus="paperType()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-col :span="24">
          <el-dialog width="80%" title="请选择试卷分类" :visible.sync="paperVisible" append-to-body>
            <div class="app-container">
              <el-form
                :model="pqueryParams"
                ref="pqueryForm"
                :inline="true"
                v-show="pshowSearch"
                label-width="68px"
              >
                <el-form-item label="名称" prop="name">
                  <el-input
                    v-model="pqueryParams.name"
                    placeholder="请输入名称"
                    clearable
                    size="small"
                    @keyup.enter.native="phandleQuery"
                  />
                </el-form-item>
                <el-form-item label="其他描述" prop="other">
                  <el-input
                    v-model="pqueryParams.other"
                    placeholder="请输入其他描述"
                    clearable
                    size="small"
                    @keyup.enter.native="phandleQuery"
                  />
                </el-form-item>
                <el-form-item>
                  <el-button
                    type="primary"
                    icon="el-icon-search"
                    size="mini"
                    @click="phandleQuery"
                  >搜索</el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="presetQuery">重置</el-button>
                </el-form-item>
              </el-form>

              <el-table
                v-loading="ploading"
                :data="ppaper_typeList"
                @row-click="prowclick($event)"
                highlight-current-row
              >
                <el-table-column type="index" width="55" align="center" />

                <el-table-column label="名称" align="center" prop="name" />
                <el-table-column label=" 创建人" align="center" prop="createBy" />
                <el-table-column label="创建时间" align="center" prop="createTime" width="180">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="修改人" align="center" prop="updateBy" />
                <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
                  <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="其他描述" align="center" prop="other" />
              </el-table>

              <pagination
                v-show="ptotal>0"
                :total="ptotal"
                :page.sync="pqueryParams.pageNum"
                :limit.sync="pqueryParams.pageSize"
                @pagination="pgetList"
              />
              <div slot="footer" class="dialog-footer">
                <el-button @click="closePaperDialogF">取 消</el-button>
                <el-button type="primary" @click="closePaperDialogT">确 定</el-button>
              </div>
            </div>
          </el-dialog>
        </el-col>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['paper:paper:add']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['paper:paper:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['paper:paper:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['paper:paper:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="paperList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="试卷id" align="center" prop="id" />
      <el-table-column label="试卷名称" :show-overflow-tooltip="true" align="center" prop="name" />
      <el-table-column label="模板名称" :show-overflow-tooltip="true" align="center" prop="autoName" />
      <el-table-column label="试卷总分" align="center" prop="score" />
      <el-table-column label="考试时长(分钟)" align="center" prop="duration" />
      <el-table-column label="试卷平均难度" align="center" prop="difficulty" />
      <!-- <el-table-column label="试卷状态" align="center"  /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleCheck(scope.row)"
          >预览</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button> -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 预览整张试卷 -->

    <el-dialog width="80%" title :visible.sync="paper" v-if="paper">
      <showpaper :row="paperdata"></showpaper>
    </el-dialog>
    <!-- 添加或修改试卷对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" v-loading="loading">
      <el-row :gutter="15">
        <el-form ref="form" :model="form" :rules="rules" size="medium" label-width="120px">
          <el-col :span="12">
            <el-form-item label="试卷模板" prop="paperTemplateId">
              <el-select
                v-model="form.paperTemplateId"
                placeholder="请选择试卷模板"
                @change="handleexammodel()"
                clearable
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in field105Options"
                  :key="index"
                  :label="item.name"
                  :value="item.paperTemplateId"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="模板名称" prop="autoName">
              <el-input
                v-model="form.autoName"
                placeholder="请输入自动组卷模板名称"
                clearable
                :style="{width: '100%'}"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24"></el-col>
          <el-col :span="12">
            <el-form-item label="所属题库" prop="autoQuestionId">
              <el-select
                v-model="form.autoQuestionId"
                placeholder="请选择所属题库"
                @change="handlebankTypeId"
                clearable
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in bankTypeIdoption"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

           <el-col :span="12">
            <el-form-item label="关联课程" prop="courseId">
              <el-select v-model="form.courseId" placeholder="请选择课程" class="width100">
                  <el-option
                    v-for="item in courseList"
                    :key="item.id"
                    :label="item.courseName"
                    :value="item.id"
                  ></el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24"></el-col>



          <!-- <el-col :span="4">
            <el-form-item label="试卷总分" prop="score">
              <el-input
                v-model="form.score"
                placeholder="请选择试卷模板"
                :disabled="true"
                clearable
                :style="{width: '100%'}"
              ></el-input>
            </el-form-item>
          </el-col> -->

          <el-col :span="6">
            <el-form-item label="考试时长(分钟)" prop="duration">
              <el-input
                v-model="form.duration"
                placeholder="请选择试卷模板"
                :disabled="true"
                clearable
                :style="{width: '100%'}"
              ></el-input>
            </el-form-item>
          </el-col>

          <!-- <el-col :span="4">
            <el-form-item label="试卷平均难度" prop="difficulty">
              <el-input
                v-model="form.difficulty"
                placeholder="请选择试卷模板"
                :disabled="true"
                clearable
                :style="{width: '100%'}"
              ></el-input>
            </el-form-item>
          </el-col> -->
          <el-col :span="24"></el-col>
          <el-col :span="6" v-show="false">
            <el-form-item label="组卷方式" prop="tempflag">
              <el-select
                v-model="form.tempflag"
                placeholder="请选择组卷方式"
                clearable
                disabled
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in field104Options"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="6">
            <el-form-item label="所属卷库" prop="volume">
              <el-input
                v-model="form.volumeLibraryName"
                placeholder="请选择所属卷库"
                clearable
                :style="{width: '100%'}"
                @focus="volume()"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="试卷分类" prop="paperType">
              <el-input
                v-model="form.paperTypeName"
                placeholder="请选择试卷分类"
                clearable
                :style="{width: '100%'}"
                @focus="paperType()"
              ></el-input>
            </el-form-item>
          </el-col> -->
          <!-- <el-col :span="6">
            <el-form-item label="组卷数量" prop="count" >
              <el-input
                v-model="form.count"
                placeholder="请输入组卷数量"
                clearable
                type="number"
                :style="{width: '100%'}"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-dialog width="80%" title="请选择所属卷库" :visible.sync="volumeVisible" append-to-body>
              <div class="app-container">
                <el-form
                  :model="vqueryParams"
                  ref="vqueryForm"
                  :inline="true"
                  v-show="vshowSearch"
                  label-width="68px"
                >
                  <el-form-item label="课程关联id" prop="classesId">
                    <el-input
                      v-model="vqueryParams.classesId"
                      placeholder="请输入课程关联id"
                      clearable
                      size="small"
                      @keyup.enter.native="vhandleQuery"
                    />
                  </el-form-item>
                  <el-form-item label="卷库名称" prop="name">
                    <el-input
                      v-model="vqueryParams.name"
                      placeholder="请输入卷库名称"
                      clearable
                      size="small"
                      @keyup.enter.native="vhandleQuery"
                    />
                  </el-form-item>
                  <el-form-item label="卷库编号" prop="code">
                    <el-input
                      v-model="vqueryParams.code"
                      placeholder="请输入卷库编号"
                      clearable
                      size="small"
                      @keyup.enter.native="vhandleQuery"
                    />
                  </el-form-item>
                  <el-form-item label="卷库状态" prop="state">
                    <el-input
                      v-model="vqueryParams.state"
                      placeholder="请输入卷库状态"
                      clearable
                      size="small"
                      @keyup.enter.native="vhandleQuery"
                    />
                  </el-form-item>
                  <el-form-item>
                    <el-button
                      type="primary"
                      icon="el-icon-search"
                      size="mini"
                      @click="vhandleQuery"
                    >搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="vresetQuery">重置</el-button>
                  </el-form-item>
                </el-form>

                <el-table
                  v-loading="vloading"
                  :data="vlibraryList"
                  @row-click="vrowclick($event)"
                  highlight-current-row
                >
                  <el-table-column type="index" width="55" align="center" />
                  <el-table-column label="卷库名称" align="center" prop="name" />
                  <el-table-column label="卷库编号" align="center" prop="code" />
                  <el-table-column label="卷库描述" align="center" prop="other" />
                  <el-table-column label="卷库状态" align="center" prop="state" />
                </el-table>

                <pagination
                  v-show="vtotal>0"
                  :total="vtotal"
                  :page.sync="vqueryParams.pageNum"
                  :limit.sync="vqueryParams.pageSize"
                  @pagination="vgetList"
                />
                <div slot="footer" class="dialog-footer">
                  <el-button @click="closeVolumeDialogF">取 消</el-button>
                  <el-button type="primary" @click="closeVolumeDialogT">确 定</el-button>
                </div>
              </div>
            </el-dialog>
          </el-col> -->

          <!-- <el-col :span="24">
            <el-dialog width="80%" title="请选择试卷分类" :visible.sync="paperVisible" append-to-body>
              <div class="app-container">
                <el-form
                  :model="pqueryParams"
                  ref="pqueryForm"
                  :inline="true"
                  v-show="pshowSearch"
                  label-width="68px"
                >
                  <el-form-item label="名称" prop="name">
                    <el-input
                      v-model="pqueryParams.name"
                      placeholder="请输入名称"
                      clearable
                      size="small"
                      @keyup.enter.native="phandleQuery"
                    />
                  </el-form-item>
                  <el-form-item label="其他描述" prop="other">
                    <el-input
                      v-model="pqueryParams.other"
                      placeholder="请输入其他描述"
                      clearable
                      size="small"
                      @keyup.enter.native="phandleQuery"
                    />
                  </el-form-item>
                  <el-form-item>
                    <el-button
                      type="primary"
                      icon="el-icon-search"
                      size="mini"
                      @click="phandleQuery"
                    >搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="presetQuery">重置</el-button>
                  </el-form-item>
                </el-form>

                <el-table
                  v-loading="ploading"
                  :data="ppaper_typeList"
                  @row-click="prowclick($event)"
                  highlight-current-row
                >
                  <el-table-column type="index" width="55" align="center" />

                  <el-table-column label="名称" align="center" prop="name" />
                  <el-table-column label=" 创建人" align="center" prop="createBy" />
                  <el-table-column label="创建时间" align="center" prop="createTime" width="180">
                    <template slot-scope="scope">
                      <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="修改人" align="center" prop="updateBy" />
                  <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
                    <template slot-scope="scope">
                      <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
                    </template>
                  </el-table-column>
                  <el-table-column label="其他描述" align="center" prop="other" />
                </el-table>

                <pagination
                  v-show="ptotal>0"
                  :total="ptotal"
                  :page.sync="pqueryParams.pageNum"
                  :limit.sync="pqueryParams.pageSize"
                  @pagination="pgetList"
                />
                <div slot="footer" class="dialog-footer">
                  <el-button @click="closePaperDialogF">取 消</el-button>
                  <el-button type="primary" @click="closePaperDialogT">确 定</el-button>
                </div>
              </div>
            </el-dialog>
          </el-col> -->

          <el-col :span="24">
            <el-dialog
              title
              :visible.sync="outvisable"
              v-if="outvisable"
              width="80%"
              append-to-body
              center
            >
              <div v-if="judegtype">
                <search :row="{searchitem,exitem}" @componentdata="componentdata"></search>
              </div>
              <div v-if="!judegtype">
                <showitem :row="shwo"></showitem>
              </div>
            </el-dialog>
            <el-dialog
              width="50%"
              title="小题详情"
              :visible.sync="innerVisible"
              v-if="innerVisible"
              append-to-body
            >
              <showDetail :row="propdata"></showDetail>
            </el-dialog>

            <div v-for="(item,i) in form.structureList" :key="i" v-show="form.tempflag!=null">
              <div class="container">
                <span
                  class="number"
                >{{item.name}} {{item.score}}分 共{{item.count}}题 已选{{item.templatecount}}题 该大题平均难度{{item.difficulty}}</span>
                <el-button
                  type="success"
                  @click="checkcontianer(i)"
                  plain
                  round
                  :disabled="item.templatecount==0"
                  v-show="form.tempflag==2"
                >预览大题</el-button>
                <!-- <el-button type="success" @click="checkcontianer(i)" :disabled="!(form.structureList[i].bankList!=null&&form.structureList[i].count==form.structureList[i].bankList.length)" plain round>预览大题</el-button> -->
              </div>
              <!-- 这里是选择的地方 -->
              <!-- <el-dialog width="60%" title="小题合集" @close="item.outvisable=false" :visible.sync="item.outvisable" append-to-body> -->
              <el-collapse v-model="item.quesitem" style="margin-left:100px">
                <el-collapse-item title="查看/隐藏小题">
                  <div>
                    <div class="questitem">
                      <div class="questdetail" v-for="item2 in item.count" :key="item2">
                        <span
                          style="color:#E6A23C"
                          v-if="item.bankList[item2-1]==null&&item.structureList[item2-1]==''"
                        >请选择小题</span>
                        <span
                          style="margin-left:10px"
                          v-if="item.bankList[item2-1]!=null||item.structureList[item2-1]!=''"
                        >第{{item2}}题</span>
                        <el-button
                          type="primary"
                          :disabled="form.autoQuestionId==null"
                          style="margin-left:10px;margin-right:5px"
                          @click="handdeeletip(i,item2-1,item)"
                          size="mini"
                          round
                        >
                          <i class="el-icon-edit"></i>
                        </el-button>
                        <el-button
                          type="success"
                          v-show="form.tempflag==2"
                          style="margin-right:10px"
                          @click="handonecheck(i,item2-1,item)"
                          size="mini"
                          round
                        >
                          <i class="el-icon-view"></i>
                        </el-button>
                      </div>
                    </div>
                  </div>
                </el-collapse-item>
              </el-collapse>
            </div>
          </el-col>
          <el-col :span="24">
            <el-form-item size="large" style="margin-top:10px">
              <el-button type="primary" @click="submitForm">保存模板</el-button>
              <el-button @click="dialogresetForm">重置</el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <!-- 自动组卷选题 -->
      <el-dialog width="40%" title="自动组卷小题" :visible.sync="selfecontainer" append-to-body>
        <div>
          <el-form
            ref="selfeformData"
            :model="selfeformData"
            :rules="selferules"
            size="medium"
            label-width="100px"
          >
            <el-form-item label="题目模板" prop="questionTemplateId">
              <el-select
                v-model="selfeformData.questionTemplateId"
                placeholder="请选择模板分类"
                clearable
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in formworkOptions"
                  :key="index"
                  :label="item.label"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="所属章节" prop="chapterId">
              <el-select
                v-model="selfeformData.chapterId"
                default-first-option
                @focus="handlequestionTemplateId(1)"
                placeholder="请选择所属章节"
                clearable
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in field101Options"
                  :key="index"
                  :label="item"
                  :value="item"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="一级知识点" prop="knowledgeA">
              <el-select
                v-model="selfeformData.knowledgeA"
                placeholder="请选择一级知识点"
                clearable
                @focus="handlequestionTemplateId(2)"
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in knowledgeAOptions"
                  :key="index"
                  :label="item"
                  :value="item"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="二级知识点" prop="knowledgeB">
              <el-select
                v-model="selfeformData.knowledgeB"
                placeholder="请选择二级知识点"
                clearable
                @focus="handlequestionTemplateId(3)"
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in knowledgeBOptions"
                  :key="index"
                  :label="item"
                  :value="item"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="考核知识点" prop="investigateKnow">
              <el-select
                v-model="selfeformData.investigateKnow"
                placeholder="请选择考核知识点"
                clearable
                @focus="handlequestionTemplateId(4)"
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in investigateKnowOptions"
                  :key="index"
                  :label="item"
                  :value="item"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="知识分类" prop="categorization">
              <el-select
                v-model="selfeformData.categorization"
                placeholder="请选择知识分类"
                clearable
                @focus="handlequestionTemplateId(5)"
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in categorizationOptions"
                  :key="index"
                  :label="item"
                  :value="item"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="难度" prop="difficulty">
              <el-select
                v-model="selfeformData.difficulty"
                placeholder="请选择难度"
                clearable
                @focus="handlequestionTemplateId(6)"
                @blur="changedifficulty()"
                :style="{width: '100%'}"
              >
                <el-option
                  v-for="(item, index) in difficultyOptions"
                  :key="index"
                  :label="item"
                  :value="item"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item size="large">
              <el-button type="primary" @click="submitselfeformData">提交</el-button>
              <el-button @click="selferesetForm">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-dialog>
    </el-dialog>
  </div>
</template>


<script>
  import {
    exportPaper,
  } from "@/api/paper/paper";
  import {
    listTemplate,
    getTemplate,
    delTemplate,
  } from "@/api/paper/template";
  import {
    getChapte,
    getKnowledgeA,
    getKnowledgeB,
    getInvestigateKnow,
    getCategorization,
    getDifficulty,
    addselfePaper,
    listautoPaper,
    getautoPaperdetail
  } from "@/api/paper/Automatic";

  import showDetail from "@/components/showDetail";
  import search from "./search.vue";
  import showitem from "./showitem.vue";
  import showpaper from "./showpaper.vue";
  import { listTemplatemoble } from "@/api/topic/template";
  import { listQuestionbank } from "@/api/topic/questionbank";

  import { volume } from "@/assets/mixins/volume";
  import { paperType } from "@/assets/mixins/paperType";
  import { listCourse } from "@/api/org/course";
  import {
    listQuestionBankType,
  } from "@/api/topic/QuestionBankType";
  export default {
    name: "Paper",
    components: { showDetail: showDetail, search, showitem, showpaper },
    mixins: [volume, paperType],
    data() {
      return {
         //课程选择
      courseList: [],
        //是否显示已选小题
        quesitem: false,
        //小题合集的dialog
        outvisable: false,
        //内部的dialog
        innerVisible: false,
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 试卷表格数据
        paperList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        //是否显示试卷预览
        paper: false,
        //试卷预览的数据
        paperdata: [],
        //传递到详情的数据
        propdata: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          autoName:null,
          score: null,
          duration: null,
          difficulty: null,
          paperTypeName:null,
          paperTypeId:null,
        },
        //判断是大题预览还是小题预览
        judegtype: "",
        // structureList
        structureListI: "",
        //中间变量
        templateindex: "",
        //搜索小题
        searchitem: "",
        //已存在的小题
        exitem: [],
        //预览题目
        shwo: "",
        //自动组卷选择题目
        selfecontainer: false,
        //小题信息
        smollt: [],
        //试卷模板
        field103Options: [],
        // 表单参数
        form: {
          name: undefined,
          autoName:null,
          courseId: null,
          bankTypeId: undefined,
          duration: undefined,
          score: undefined,
          paperTemplateId: undefined,
          field107: undefined,
          tempflag: 1,
          count:1,
          difficulty: undefined,
          volumeLibraryName: undefined,
          // 所属题库id
          volumeLibraryId: undefined,
          // 所属试卷分类id
          autoQuestionId:undefined,
          paperTypeId: undefined,
          paperTypeName: undefined,
        },

        //自动组卷的数据
        selfeformData: {
          bankTypeId: undefined,
          chapterId: undefined,
          knowledgeA: undefined,
          knowledgeB: undefined,
          questionScore: undefined,
          investigateKnow: undefined,
          categorization: undefined,
          difficulty: undefined,
          questionTemplateId: undefined,
        },
        selferules: {
          questionTemplateId: [
            {
              required: true,
              message: "请选择题型模板",
              trigger: "change",
            },
          ],
          chapterId: [
            {
              required: false,
              message: "请选择所属章节",
              trigger: "change",
            },
          ],
          knowledgeA: [
            {
              required: false,
              message: "请选择一级知识点",
              trigger: "change",
            },
          ],
          knowledgeB: [
            {
              required: false,
              message: "请选择二级知识点",
              trigger: "change",
            },
          ],
          investigateKnow: [
            {
              required: false,
              message: "请选择考核知识点",
              trigger: "change",
            },
          ],
          categorization: [
            {
              required: false,
              message: "请选择难度",
              trigger: "change",
            },
          ],
          difficulty: [
            {
              required: false,
              message: "请选择知识分类",
              trigger: "change",
            },
          ],
        },
        // 所属题库
        bankTypeIdoption: [],
        formworkOptions: [],
        field101Options: [],
        knowledgeAOptions: [],
        knowledgeBOptions: [],
        investigateKnowOptions: [],
        categorizationOptions: [],
        difficultyOptions: [],
        //临时保存点击的位置
        temposition: "",
        // 表单校验
        rules: {
          field105: [
            {
              required: true,
              message: "请选择试卷模板",
              trigger: "change",
            },
          ],
          tempflag: [
            {
              required: true,
              message: "请选择组卷方式",
              trigger: "change",
            },
          ],
          questionTypeId: [
            {
              required: true,
              message: "请选择所属题库",
              trigger: "blur",
            },
          ],
          count: [
            {
              required: true,
              message: "请输入试卷数量",
              trigger: "blur",
            },
          ],
          autoName: [
            {
              required: true,
              message: "请输入模板名称",
              trigger: "blur",
            },
          ],
          field108: [
            {
              required: true,
              message: "请输入试卷总分",
              trigger: "blur",
            },
          ],
          field107: [
            {
              required: true,
              message: "请输入考试时长(分钟)",
              trigger: "blur",
            },
          ],
          paperTemplateId: [
            {
              required: true,
              message: "请选择试卷模板",
              trigger: "blur",
            },
          ],
          difficulty: [
            {
              required: true,
              message: "请输入试卷平均难度",
              trigger: "blur",
            },
          ],
        },
        field105Options: [
          {
            label: "选项一",
            value: 1,
          },
          {
            label: "选项二",
            value: 2,
          },
        ],
        field104Options: [
          {
            label: "自动组卷",
            value: 1,
          },
          {
            label: "手动组卷",
            value: 2,
          },
        ],
      };
    },
    created() {
      this.getList();
      this.getbanketypeop();
    },
    methods: {
      //选择难度后重置为浮点类型
      changedifficulty(){
        this.form.difficulty=parseFloat(this.form.difficulty).toFixed(1)
      },
      // 选择了模板分类后
      handlequestionTemplateId(data) {
        this.getoptions(data);
      },
      //选择题库
      handlebankTypeId() {
        console.log( this.form.autoQuestionId,"sdadsa")
        this.selfeformData.bankTypeId = this.form.autoQuestionId;
      },
      //获取题库列表
      getbanketypeop() {
        listQuestionBankType(this.queryParams).then((response) => {
          this.bankTypeIdoption = response.rows;
        });
      },
      // 获取选择小题时其他的数组
      getoptions(data) {
        if (data == 1) {
          getChapte(this.selfeformData).then((response) => {
            this.field101Options = response;
          });
        } else if (data == 2) {
          getKnowledgeA(this.selfeformData).then((response) => {
            this.knowledgeAOptions = response;
          });
        } else if (data == 3) {
          getKnowledgeB(this.selfeformData).then((response) => {
            this.knowledgeBOptions = response;
          });
        } else if (data == 4) {
          getInvestigateKnow(this.selfeformData).then((response) => {
            this.investigateKnowOptions = response;
          });
        } else if (data == 5) {
          getCategorization(this.selfeformData).then((response) => {
            this.categorizationOptions = response;
          });
        } else if (data == 6) {
          getDifficulty(this.selfeformData).then((response) => {
            this.difficultyOptions = response;
          });
        }

      },
      //获取题型模板类型
      getFormarkdata(mybeanName) {
        const data = {
          beanName: mybeanName,
        };
        listTemplatemoble(data).then((response) => {
          this.formworkOptions = response.rows;
          for (let i = 0; i < response.rows.length; i++) {
            this.formworkOptions[i].label = response.rows[i].name;
            this.formworkOptions[i].value = response.rows[i].name;
          }
        });
      },
      //自动组卷提交
      submitselfeformData() {
        this.$refs["selfeformData"].validate((valid) => {
          if (valid) {
            //把分数存入小题里面
            for(let k=0;k<this.formworkOptions.length;k++){
              if(this.formworkOptions[k].id==this.selfeformData.questionTemplateId){
                this.selfeformData.questionScore=this.formworkOptions[k].questionScore
              }
            }
            this.form.structureList[this.temposition].structureList[
              this.templateindex
              ] = this.selfeformData;
            this.form.structureList[this.temposition].templatecount=this.form.structureList[this.temposition].structureList.length
            this.form.structureList[this.temposition].difficulty = parseFloat(
              [
                parseFloat(this.form.structureList[this.temposition].difficulty *
                  (this.form.structureList[this.temposition].structureList.length-1) +
                  this.selfeformData.difficulty)
              ] / this.form.structureList[this.temposition].structureList.length
            ).toFixed(1);
            var sumtotal = parseFloat(0);
            for (let j = 0; j < this.form.structureList.length; j++) {
              sumtotal += parseFloat(this.form.structureList[j].difficulty);
              console.log( sumtotal)
            }
            this.form.difficulty = parseFloat(
              parseFloat(sumtotal).toFixed(1) / this.form.structureList.length
            ).toFixed(1);
            this.selfecontainer = false;
          }
          // TODO 提交表单
        });
      },
      selferesetForm() {
        this.selfeformData = {
          field101: undefined,
          knowledgeA: undefined,
          questionScore: undefined,
          knowledgeB: undefined,
          investigateKnow: undefined,
          categorization: undefined,
          difficulty: undefined,
          questionTemplateId: undefined,
          bankTypeId: this.form.autoQuestionId,
        };
      },
      //联级选择器
      cascader() {
        console.log("联级", this.cascaderselectedOptions3);
      },

      //表单重置
      dialogresetForm() {
        this.form = {
          name: undefined,
          autoName:undefined,
          courseId: null,
          duration: undefined,
          score: undefined,
          count:1,
          paperTemplateId: undefined,
          field107: undefined,
          difficulty: undefined,

          volumeLibraryName: undefined,
          // 所属题库id
          volumeLibraryId: undefined,
          // 所属试卷分类id
          paperTypeId: undefined,
          paperTypeName: undefined,
          autoQuestionId:undefined,
        };
      },
      ////点击小题后添加,接受子组件传值
      componentdata(componentdata) {
        this.form.structureList[this.structureListI].bankList[
          this.templateindex
          ] = componentdata;
        this.form.structureList[this.structureListI].bankList[
          this.templateindex
          ].paperOrdered = this.templateindex;
        //计算难度
        let sum = 0;
        for (
          let i = 0;
          i < this.form.structureList[this.structureListI].bankList.length;
          i++
        ) {
          if (
            this.form.structureList[this.structureListI].bankList[i] != undefined
          ) {
            sum +=
              this.form.structureList[this.structureListI].bankList[i].difficulty;
          }
        }
        this.form.structureList[this.structureListI].difficulty = parseFloat(
          sum / this.form.structureList[this.structureListI].bankList.length
        ).toFixed(1);
        var sumtotal = parseFloat(0);
        for (let j = 0; j < this.form.structureList.length; j++) {
          sumtotal += parseFloat(this.form.structureList[j].difficulty);
        }

        this.form.difficulty = parseFloat(
          parseFloat(sumtotal).toFixed(1) / this.form.structureList.length
        ).toFixed(1);

        this.form.structureList[this.structureListI].templatecount =
          this.form.structureList[this.structureListI].bankList.length;
        this.$message({
          message: "添加成功",
          type: "success",
        });
        this.outvisable = false;
      },
      /** 查询试卷列表 */
      getList() {
        this.loading = true;
        listautoPaper(this.queryParams).then((response) => {
          this.paperList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
        listTemplate().then((response) => {
          this.field105Options = response.rows;
          for (let i = 0; i < this.field105Options.length; i++) {
            this.field105Options[i].paperTemplateId = this.field105Options[i].id;
            this.field105Options[i].id = null;
          }
        });
       listCourse().then((response) => {
        this.courseList = response.rows;
        console.log(this.courseList);
      });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          classesId: null,
          createBy: null,
          createduration: null,
          updateBy: null,
          updateduration: null,
          name: null,
          score: null,
          duration: null,
          difficulty: null,
          tempflag: 1,
          volumeLibraryName: null,
          // 所属题库id
          volumeLibraryId: null,
          // 所属试卷分类id
          paperTypeId: null,
          paperTypeName: null,
        };
        this.resetForm("form");
      },
      //选择了试卷模板
      handleexammodel() {
        getTemplate(this.form.paperTemplateId).then((response) => {
          this.form = response.data;
          this.form.tempflag = 1;
          this.form.duration = this.form.time;
          this.form.paperTemplateId = response.data.id;
          this.form.id = null;
          for (let i = 0; i < this.form.structureList.length; i++) {
            this.form.structureList[i].outvisable = false;
            this.form.structureList[i].quesitem = 1;
            this.form.structureList[i].structureList = [];
            for (let j = 0; j < this.form.structureList[i].count; j++) {
              this.form.structureList[i].structureList[j] = [];
            }
            this.form.structureList[i].difficulty = 0;
            this.form.structureList[i].score = parseFloat(
              this.form.structureList[i].score
            );
            this.form.structureList[i].templatecount = 0;
            this.form.structureList[i].bankList = [];
          }
        });
      },

      //预览小题详细
      handonecheck(findex, sindex, item) {
        if (this.form.structureList[findex].bankList[sindex] == null) {
          this.$confirm("请先选择小题", "警告", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              this.handdeeletip(findex, sindex, item);
            })
            .catch(() => {});
        } else {
          this.propdata = this.form.structureList[findex].bankList[sindex];
          this.innerVisible = true;
        }
      },
      //预览一道大题内部的所有小题
      checkcontianer(item) {
        if (this.form.structureList[item].bankList == null) {
          this.$message({
            message: "请先选择小题",
            type: "warning",
          });
        } else {
          this.outvisable = true;
          this.judegtype = false;
          this.shwo = this.form.structureList[item];
        }
      },
      //添加试卷时候点击修改小题后
      handdeeletip(index, temindex, templaitem) {
        this.getFormarkdata(this.form.structureList[index].beanName);
        this.field101Options=[]
        this.knowledgeAOptions=[]
        this.knowledgeBOptions=[]
        this.investigateKnowOptions= []
        this.categorizationOptions=[]
        this.difficultyOptions= []
        if (this.form.tempflag == 2) {
          this.judegtype = true;
          this.searchitem = templaitem;
          this.exitem = this.form.structureList[index].bankList;
          const data = {
            beanName: this.form.structureList[index].beanName,
            questionTemplateId: this.form.structureList[index].questionTemplateId,
          };
          this.structureListI = index;
          listQuestionbank(data).then((response) => {
            this.smollt = response.rows;
          });
          this.outvisable = true;
          this.templateindex = temindex;
        } else {
          this.temposition = index;
          this.selfecontainer = true;
          this.templateindex = temindex;
          this.selferesetForm();
        }
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map((item) => item.id);
        this.single = selection.length !== 1;
        this.multiple = !selection.length;
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加自动组卷模板";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const ids = row.id || this.ids;
        let that = this
        getautoPaperdetail(ids).then((response) => {
          that.form = response
          that.form.tempflag=1
          for (let i = 0; i < that.form.structureList.length; i++) {
            if (that.form.structureList[i].bankList == []) {
              that.form.structureList[i].templatecount = 0;
            } else {
              that.form.structureList[i].templatecount =
                that.form.structureList[i].bankList.length;
              let sum = 0;
              for (
                let j = 0;
                j < that.form.structureList[i].bankList.length;
                j++
              ) {
                sum += that.form.structureList[i].bankList[j].difficulty;
              }
              that.form.structureList[i].difficulty = parseFloat(
                sum / that.form.structureList[i].bankList.length
              ).toFixed(1);
            }
          }
          that.open = true;
          that.title = "修改试卷";
        });
      },
      //处理每一题总分
      checkscor(data){
         for(let i=0;i<data.structureList.length;i++){
           data.structureList[i].score=0
           for(let j=0;j<data.structureList[i].structureList.length;j++){
               data.structureList[i].score+=data.structureList[i].structureList[j].questionScore
           }
         }
      },
      //预览整张试卷
      handleCheck(row) {
        
        const ids = row.id || this.ids;
        // this.paperdata = {
        //   id: ids,
        // };
        getautoPaperdetail(ids).then((response) => {
           this.paperdata=response
           this.paper = true;
          console.log("试卷222",response)
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate((valid) => {
          if (valid) {
            this.form.count=parseInt(this.form.count)
            this.loading = true;
            if (this.form.id != null) {
              // updatePaper(this.form).then((response) => {
              //   this.msgSuccess("修改成功");
              //   // this.loading=false
              //   this.open = false;
              //   this.getList();
              //   this.reset();

              // });
            } else {
              addselfePaper(this.form).then((response) => {
                this.msgSuccess("新增成功");
                // this.loading=false
                this.open = false;
                this.getList();
                this.reset();
              });
            }
            this.loading = false;
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除自动组卷模板编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(function () {
            return delTemplate(ids);
          })
          .then(() => {
            this.getList();
            this.msgSuccess("删除成功");
          })
          .catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm("是否确认导出所有试卷数据项?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.exportLoading = true;
            return exportPaper(queryParams);
          })
          .then((response) => {
            this.download(response.msg);
            this.exportLoading = false;
          })
          .catch(() => {});
      },
    },
  };
</script>
<style scoped>
  .questitem {
    display: flex;
    flex-flow: wrap;
    margin-bottom: 20px;
    margin-left: 10px;
    background-color: #ebeef5;
  }
  .questdetail {
    margin-top: 5px;
    margin-bottom: 5px;
    margin-left: 10px;
    height: 48px;
    padding-left: 5px;
    line-height: 48px;
    /* width: 12%; */
    border-radius: 30px;
    background-color: #fff;
    border: 1px solid #e4e7ed;
  }
  .questdetail1 {
    margin-top: 5px;
    margin-bottom: 5px;
    margin-left: 10px;
    height: 48px;
    padding-left: 5px;
    line-height: 48px;
    /* width: 15%; */
    border-radius: 30px;
    background-color: #fff;
    border: 1px solid #e4e7ed;
  }
  .number {
    display: block;
    height: 36px;
    margin-right: 20px;
    width: 400px;
    color: #303133;
    line-height: 36px;
    text-align: center;
    border: 1px solid #67c23a;
  }
  .container {
    display: flex;
    margin-left: 100px;
    margin-bottom: 10px;
    margin-top: 10px;
  }
</style>
